package ua.org.enginer.utils
{
	import com.dynamicflash.util.Base64;
	
	public class Cryptor
	{
		private static function xor(source:String, key:String=""):String {
            if (!key) return source;
            
            var keyLength:int = key.length;
            var result:String = "";
            
            for(var i:Number = 0; i < source.length; i++) 
                result += String.fromCharCode(source.charCodeAt(i) ^ key.charCodeAt(i % keyLength));
            
            return result;
        }
 
        public static function encode(source:String, key:String=""):String {
            return xor(Base64.encode(source), key);
        }
 
        public static function decode(source:String, key:String=""):String {
          	return Base64.decode(xor(source, key));
        }
	}
}